// 床位表模拟数据
require("../models/relation")
const mock = require("mockjs")
const {Bednumber} = require("../models/Bednumber")
const {RoomNo} = require("../models/RoomNo")

RoomNo.findAll().then(data => {
    const arr = JSON.parse(JSON.stringify(data))
    // 床位号数组
    let bednumberId = [];
    for (const key in arr) {
        for(let i = 0; i < arr[key].roomCapacity; i++){
            bednumberId.push(i + 1 + "号床")
        }
    }
    
    // 是否住人数组
    let isPeopleArr = []
    for (const key in arr) {
        let isPeople  = new Array(+arr[key].roomCapacity).fill(0)
        for(let i = 0; i < arr[key].roomResided; i++){
            isPeople[i]++
        }
        isPeopleArr.push(...isPeople)
    }

    // 关联房间表id数组
    let RoomNoId = []    
    for (const key in arr) {
        let isPeople  = new Array(+arr[key].roomCapacity).fill(+arr[key].id)
        RoomNoId.push(...isPeople)
    }
    const BednumberList = mock.mock({
        [`datas|${bednumberId.length}`]:[
            {
                "id|+1":1,
                "bednumberId|+1":bednumberId,
                "isPeople|+1":isPeopleArr,
                "RoomNoId|+1":RoomNoId
            }
        ]
    }).datas
    console.log(BednumberList[3079]);
    Bednumber.bulkCreate(BednumberList).then(data => {
        console.log(data);
    })
})